﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// love2012 的摘要说明
/// </summary>
public class love2012
{
    public static string Conn = getsql.getstr("activestr"); //"server=.;User ID=sa;Password=wuxinjie;database=TenTianGe;Connection Reset=FALSE";//
	public love2012()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}


    public static int zhufu(int useridx, string username,string tousername1,string tousername2,string touseridx1,string touseridx2,int type)
    {
        int num = 0;

        try
        {

            SqlParameter[] p =
                    {
          
                         SqlHelper.MakeInParam("@type",SqlDbType.Int,4,type),
                        SqlHelper.MakeInParam("@useridx",SqlDbType.Int,15,useridx),
                         SqlHelper.MakeInParam("@userid",SqlDbType.VarChar,100,username),
                         SqlHelper.MakeInParam("@tousername1",SqlDbType.VarChar,100,tousername1),
                         SqlHelper.MakeInParam("@tousername2",SqlDbType.VarChar,100,tousername2),
                          SqlHelper.MakeInParam("@touseridx1",SqlDbType.VarChar,50,touseridx1),
                          SqlHelper.MakeInParam("@touseridx2",SqlDbType.VarChar,50,touseridx2),
                         SqlHelper.MakeOutParam("@returnNum",SqlDbType.Int,4)
                 
                    };
            SqlHelper.ExecuteNonQuery(Conn, CommandType.StoredProcedure, "[pr_love2012_win]", p);
            num = int.Parse(p[7].Value.ToString());
        }
        catch
        {
            
        }

        return num;
    }

    public static int[] GetReward(long useridx, string username)
    {
        int[] num = new int[3];

        try
        {

            SqlParameter[] p =
                    {
          
                         SqlHelper.MakeInParam("@type",SqlDbType.Int,4,1),
                        SqlHelper.MakeInParam("@useridx",SqlDbType.Int,15,useridx),
                         SqlHelper.MakeInParam("@userid",SqlDbType.VarChar,100,username),
                        SqlHelper.MakeOutParam("@money",SqlDbType.Int,4),
                        SqlHelper.MakeOutParam("@yz",SqlDbType.Int,4),
                         SqlHelper.MakeOutParam("@returnNum",SqlDbType.Int,4)
                 
                    };
            SqlHelper.ExecuteNonQuery(Conn, CommandType.StoredProcedure, "[pr_love2012]", p);
            num[0] = int.Parse(p[3].Value.ToString());
            num[1] = int.Parse(p[4].Value.ToString());
            num[2] = int.Parse(p[5].Value.ToString());
        }
        catch
        {
           
        }

        return num;
    }
    public static int GetYZ(long useridx, string username,int type)
    {
        int num = 0;

        try
        {

            SqlParameter[] p =
                    {
          
                         SqlHelper.MakeInParam("@type",SqlDbType.Int,4,type),
                        SqlHelper.MakeInParam("@useridx",SqlDbType.Int,15,useridx),
                         SqlHelper.MakeInParam("@userid",SqlDbType.VarChar,100,username),
                        SqlHelper.MakeOutParam("@money",SqlDbType.Int,4),
                        SqlHelper.MakeOutParam("@yz",SqlDbType.Int,4),
                         SqlHelper.MakeOutParam("@returnNum",SqlDbType.Int,4)
                 
                    };
            SqlHelper.ExecuteNonQuery(Conn, CommandType.StoredProcedure, "[pr_love2012]", p);

            num = int.Parse(p[4].Value.ToString());
        }
        catch
        {

        }
        
        return num;
    }
    public static string[] Load(long useridx, string username)
    {
        DataSet ds = null;
        string[] str=new string[4];
        string strTemp = string.Empty;
        str[0] = "[系统错误，请刷新]";
        str[1] = str[0];
        str[2] = str[0];
        str[3] = str[0];
        //取收取礼物排名
        try
        {

            SqlParameter[] p =
                    {
          
                         SqlHelper.MakeInParam("@type",SqlDbType.Int,4,2),
                        SqlHelper.MakeInParam("@useridx",SqlDbType.Int,15,useridx),
                        SqlHelper.MakeInParam("@userid",SqlDbType.VarChar,100,username),
                        SqlHelper.MakeOutParam("@money",SqlDbType.Int,4),
                        SqlHelper.MakeOutParam("@yz",SqlDbType.Int,4),
                         SqlHelper.MakeOutParam("@returnNum",SqlDbType.Int,4)
                 
                    };
            ds = SqlHelper.ExecuteDataset(Conn, CommandType.StoredProcedure, "[pr_love2012]", p);
        }
         
        catch
        {

        }
        if (ds != null && ds.Tables.Count >= 4)
        {
            str[0] = string.Empty;
            string html = string.Empty;
            for(int i = 0;i<ds.Tables[0].Rows.Count;i++)
            {
                str[0] += "<div class=\"us_box\"><div class=\"us_pic\"><a href=\"#\"><img src=\"common/images/p"+(i+1).ToString()+".jpg\" border=\"0\" /></a>";
                if (i == 0)
                    str[0] += "<div class=\"nu1\"></div></div>";
                else if(i==1)
                    str[0] += "<div class=\"nu2\"></div></div>";
                else if(i==2)
                    str[0] += "<div class=\"nu3\"></div></div>";
                else
                    str[0] += "<div ></div></div>";
                //html = "touseridx1=" + ds.Tables[0].Rows[i]["toidx"].ToString() + "&touseridx2=" + ds.Tables[0].Rows[i]["souidx"].ToString() + "&tousername1=" + ds.Tables[0].Rows[i]["toname"].ToString() + "&tousername2=" +ds.Tables[0].Rows[i]["souname"].ToString();
              
    html = "touseridx1=" + ds.Tables[0].Rows[i]["toidx"].ToString() + "&touseridx2=" + ds.Tables[0].Rows[i]["souidx"].ToString() + "&tousername1=" + System.Web.HttpUtility.UrlEncode(ds.Tables[0].Rows[i]["toname"].ToString(), System.Text.Encoding.GetEncoding("GB2312")).ToString() + "&tousername2=" + System.Web.HttpUtility.UrlEncode(ds.Tables[0].Rows[i]["souname"].ToString(), System.Text.Encoding.GetEncoding("GB2312")).ToString();
		str[0]+="<div class=\"us_tex\"><dl><dd>用户：<span class=\"fc01\">"
               + ds.Tables[0].Rows[i]["toname"].ToString() +"</span></dd><dd>收到礼物：<span class=\"fc01\">" + ds.Tables[0].Rows[i]["num"].ToString() + "</span></dd><dd>追求者：<span class=\"fc01\">" + ds.Tables[0].Rows[i]["souname"].ToString() 
               +"</span></dd><dd>"
               + "<input type=\"button\" name=\"zhuf\"   value=\"送祝福\"  onclick=$('#touser').attr('value','" + html + "');ZhuFuOper(); class=\"us_btn\"/>"
               + "</dd></dl></div></div>";
			}

            str[1] = ds.Tables[1].Rows[0]["num"].ToString();

            str[2] = ds.Tables[2].Rows[0]["num"].ToString();

            str[3] = ds.Tables[3].Rows[0]["num"].ToString();
        }

        return str;

    }

    public static string[] LoadInfo(long useridx, string username)
    {
        DataSet ds = null;
        string[] str = new string[3];
        string strTemp = string.Empty;
        //取收取礼物排名
        try
        {

            SqlParameter[] p =
                    {
          
                         SqlHelper.MakeInParam("@type",SqlDbType.Int,4,3),
                        SqlHelper.MakeInParam("@useridx",SqlDbType.Int,15,useridx),
                        SqlHelper.MakeInParam("@userid",SqlDbType.VarChar,100,username),
                        SqlHelper.MakeOutParam("@money",SqlDbType.Int,4),
                        SqlHelper.MakeOutParam("@yz",SqlDbType.Int,4),
                         SqlHelper.MakeOutParam("@returnNum",SqlDbType.Int,4)
                 
                    };
            ds = SqlHelper.ExecuteDataset(Conn, CommandType.StoredProcedure, "[pr_love2012]", p);
        }

        catch
        {
            str[0] = "[系统错误，请刷新]";
            str[1] = str[0];
            str[2] = str[0];
        }
        if (ds != null && ds.Tables.Count >= 3)
        {

            str[0] = ds.Tables[0].Rows[0]["num"].ToString();

            str[1] = ds.Tables[1].Rows[0]["num"].ToString();

            str[2] = ds.Tables[2].Rows[0]["num"].ToString();
        }

        return str;

    }
}
